package cn.chenxiejia;

import java.lang.reflect.Method;

/**
 * @version : V1.0
 * @program: maven
 * @ClassName: Fs1
 * @Description: 使用反射的方式打印String类中的所有方法带参数
 * @Author: chenxiejia
 * @Date: 2022/2/9 20:15
 */
public class Fs1 {
    public static void main(String[] args) {
        
        var str = String.class;
        Method[] method = str.getDeclaredMethods();
        for (Method method1 : method) {
            StringBuilder sb = new StringBuilder();
            sb.append(method1.getName()).append("(");
            //System.out.println(method1.getName());
            for (Class<?> parameterType : method1.getParameterTypes()) {
                //System.out.println(parameterType.getName());
                //sb.append(parameterType.getName());
//                if (parameterType.getName().contains(".")) {
//                    sb.append(parameterType.getName()).append(",");
//                    sb.replace(0, sb.lastIndexOf(".") + 1, "");
//                } else {
                sb.append(parameterType.getName()).append(",");
                //}
            }
            sb.append(")");
            if (sb.indexOf(",") > 0) {
                sb.replace(sb.lastIndexOf(","), sb.lastIndexOf(",") + 1, "");
            }
            System.out.println(sb);
            sb.delete(0, sb.length());
        }
    }
}
